package entity;

/**
 * @Author: wanqian
 * @Date: 2021/2/8 15:21
 */
public class HuffNode implements Comparable<HuffNode> {

    private int value;

    private HuffNode left;

    private HuffNode right;

    public HuffNode(int value) {
        this.value = value;
    }

    public HuffNode(HuffNode leftNode, HuffNode rightNode) {
        this.value = leftNode.value + rightNode.value;
        this.left = leftNode;
        this.right = rightNode;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public HuffNode getLeft() {
        return left;
    }

    public void setLeft(HuffNode left) {
        this.left = left;
    }

    public HuffNode getRight() {
        return right;
    }

    public void setRight(HuffNode right) {
        this.right = right;
    }

    public void preOrder() {
        System.out.println(this);
        if (left != null) {
            left.preOrder();
        }
        if (right != null) {
            right.preOrder();
        }
    }

    @Override
    public int compareTo(HuffNode o) {
        return this.value - o.value;
    }

    @Override
    public String toString() {
        return "HuffNode{" +
                "value=" + value +
                '}';
    }
}
